<template>
  <div class="approve">
    <!-- 顶部搜索 -->
    <el-card>
      <el-form v-model="searchDate" ref="searchRef" label-width="100px" class="demo-ruleForm">
        <el-row class="demo-ruleForm-row">
          <el-col :span="6">
            <el-form-item label="项目名称" prop="name">
              <el-input placeholder="请输入招标项目名称" v-model="searchDate.name" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开标时间" prop="value">
              <el-date-picker v-model="searchDate.value1" type="date" placeholder="选择起止日期"></el-date-picker>
              -
              <el-date-picker v-model="searchDate.value2" type="date" placeholder="选择结束日期"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4" >
            <div class="search_col">
              <el-button type="primary" size="mini" icon="el-icon-search">搜索</el-button>
              <el-button type="primary" size="mini" icon="el-icon-refresh" @click="resetForm">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <!-- 数据表格 -->
    <el-card>
      <el-table
      :data="tableDate"
      :row-class-name="tableRowClassName"
      style="width: 100%"
      border
      ref="refTable"
      :header-cell-style="{
        'background-color': '#CBD9EC',
        color: '#fff',
        'font-weight': '400',
      }"
      @selection-change="handleSelectionChange"
      @sort-change="onSortChange">
        <!-- <el-table-column
          type="selection"
          width="55">
        </el-table-column> -->
        <el-table-column width="60" label="序号" type="index"></el-table-column>
        <el-table-column prop="name" label="招标项目名称" width="260"></el-table-column>
        <el-table-column prop="info_number" label="招标编号" width="240"> </el-table-column>
        <el-table-column prop="announcement" label="公告发布时间" width="200"> </el-table-column>
        <el-table-column prop="time" label="开标时间" width="200"> </el-table-column>
        <el-table-column prop="region" label="地区" width="200"></el-table-column>
        <el-table-column prop="procurement_people" label="采购人" width="120"></el-table-column>
        <el-table-column prop="procurement_contact" label="采购联系人" width="120"> </el-table-column>
        <el-table-column prop="institutions" label="代理机构" width="120"> </el-table-column>
        <el-table-column prop="responsibility" label="项目负责人" width="120"></el-table-column>
        <el-table-column prop="mobile" label="联系方式" width="150"></el-table-column>
        <el-table-column prop="offer_one" label="第一轮报价"  width="110"></el-table-column>
        <el-table-column prop="offer_two" label="第二轮报价"  width="110"></el-table-column>
        <el-table-column prop="procurement_way" label="采购方式"></el-table-column>
        <el-table-column prop="money" label="预算/拟分包金额（万元）" sortable="custom" :sort-orders="['ascending','descending']" width="130"></el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="costClick(scope.row)">费用详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.counm"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="page.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>

  </div>
</template>

<script>
export default {
  data () {
    return {
      // 搜索数据
      searchDate: {
        name: '',
        value1: '',
        value2: ''
      },

      // 第一个表格
      tableDate: [
        {
          id: 1,
          name: '国网江西省电力有限公司上饶供电分公司集体企业2020年第002批物资类招标',
          info_number: 'JXRY2020-SR-002-JT(WZ)',
          announcement: '公告',
          time: '2020年6月6日下午16:30时1',
          region: '地区',
          procurement_people: '采购人',
          procurement_contact: '采购联系人',
          institutions: '机构1',
          responsibility: '项目负责人',
          mobile: '联系方式',
          offer_one: 0,
          offer_two: 0,
          procurement_way: '采购方式',
          money: 383.46696,
          audit_status: 0,
        },
        {
          id: 2,
          name: '国网江西省电力有限公司上饶供电分公司集体企业2020年第002批物资类招标',
          info_number: 'JXRY2020-SR-002-JT(WZ)',
          announcement: '公告',
          time: '2020年6月6日下午16:30时',
          region: '地区',
          procurement_people: '采购人',
          procurement_contact: '采购联系人',
          institutions: '机构2',
          responsibility: '项目负责人',
          mobile: '联系方式',
          offer_one: 0,
          offer_two: 0,
          procurement_way: '采购方式',
          money: 320.46696,
          audit_status: 1,
        },
        {
          id: 3,
          name: '国网江西省电力有限公司上饶供电分公司集体企业2020年第002批物资类招标',
          info_number: 'JXRY2020-SR-002-JT(WZ)',
          announcement: '公告',
          time: '2020年6月6日下午16:30时2',
          region: '地区',
          procurement_people: '采购人',
          procurement_contact: '采购联系人',
          institutions: '机构3',
          responsibility: '项目负责人',
          mobile: '联系方式',
          offer_one: 0,
          offer_two: 0,
          procurement_way: '采购方式',
          money: 373.46696,
          audit_status: 2,
        },
        {
          id: 3,
          name: '国网江西省电力有限公司上饶供电分公司集体企业2020年第002批物资类招标',
          info_number: 'JXRY2020-SR-002-JT(WZ)',
          announcement: '公告',
          time: '2020年6月6日下午16:30时3',
          region: '地区',
          procurement_people: '采购人',
          procurement_contact: '采购联系人',
          institutions: '机构3',
          responsibility: '项目负责人',
          mobile: '联系方式',
          offer_one: 0,
          offer_two: 0,
          procurement_way: '采购方式',
          money: 363.46696,
          audit_status: 3,
        },
        {
          id: 5,
          name: '国网江西省电力有限公司上饶供电分公司集体企业2020年第002批物资类招标',
          info_number: 'JXRY2020-SR-002-JT(WZ)',
          announcement: '公告',
          time: '2020年6月6日下午16:30时4',
          region: '地区',
          procurement_people: '采购人',
          procurement_contact: '采购联系人',
          institutions: '机构1',
          responsibility: '项目负责人',
          mobile: '联系方式',
          offer_one: 0,
          offer_two: 0,
          procurement_way: '采购方式',
          money: 313.46696,
          audit_status: 0,
        },
      ],

      // 分页
      page: {
        // 每页显示数据条数
        size: 5,
        // 当前页码值
        counm: 1,
      },
      total: 5,
    }
  },
  methods: {
    /**
     * 表格排序事件处理函数
     * @param {object} {column,prop,order} 列数据|排序字段|排序方式
     */
    onSortChange({ prop, order }) {
        this.tableDate.sort(this.compare(prop,order));
    },
    /**
     * 排序比较
     * @param {string} propertyName 排序的属性名
     * @param {string} sort ascending(升序)/descending(降序)
     * @return {function}
     */
    compare (propertyName, sort) {
        return function (obj1, obj2) {
            var value1 = obj1[propertyName]
            var value2 = obj2[propertyName]
            if (typeof value1 === 'string' && typeof value2 === 'string') {
                const res = value1.localeCompare(value2, 'zh')
                return sort === 'ascending' ? res : -res
            } else {
                if (value1 <= value2) {
                    return sort === 'ascending' ? -1 : 1
                } else if (value1 > value2) {
                    return sort === 'ascending' ? 1 : -1
                }
            }
        }
    },

    // 重置事件
    resetForm() {
      this.searchDate.name = '';
      this.searchDate.tiem = '';
    },

    // 隔行变色
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return 'warning-row'
      } else if (rowIndex === 3) {
        return 'success-row'
      }
      return ''
    },

    // 每页显示数据条数发生变化时触发
    handleSizeChange(newSize) {
      // console.log(newSize);
    },
    // 页码值发生变化时触发
    handleCurrentChange(newPage) {
      // console.log(newPage);
    },

    handleInput(value) {
    if (value != '') {
      if (value.indexOf('.') > -1) {
          this.thirdForm.amount = value.slice(0, value.indexOf('.') + 3)
        } else { 
          this.thirdForm.amount = value
        }
      }
    },

     // 全选
    handleSelectionChange(val) {
      this.checkboxList = val;
      console.log(this.checkboxList);
    },

    // 点击费用详情
    costClick(row) {
      this.$router.push(
        {path:`/approves/cost`}
      )
    }
  },
  created () {
  }
}
</script>

<style>
.approve{
    padding: 20px;
}
.right {
  text-align: right;
}
.right i{
  font-size: 30px;
}

.ipt {
  width: 222px;
}
</style>